package controller

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"password-verification-management-system/service"
)

func GoIndex(c *gin.Context) {
	c.HTML(200, "index.html", nil)
}
func GoLogin(c *gin.Context) {
	c.HTML(200, "login.html", nil)
}
func GoRegister(c *gin.Context) {
	c.HTML(200, "register.html", nil)
}
func RegisterAdmin(c *gin.Context) {
	var registeradminservice service.AdminService
	if err := c.ShouldBind(&registeradminservice); err == nil {
		res := registeradminservice.AdminRegister(c.Request.Context())
		c.JSON(200, res)
	} else {
		c.JSON(400, err)
		c.Redirect(301, "/")
	}

}
func Go404(c *gin.Context) {
	// 实现内部重定向
	c.HTML(http.StatusOK, "404.html", gin.H{
		"title": "404",
	})

}

func GetCodeAdmin(c *gin.Context) {
	var getcodeadminservice service.AdminService
	if err := c.ShouldBind(&getcodeadminservice); err == nil {
		res := getcodeadminservice.AdminGetCode(c.Request.Context())
		c.JSON(200, res)
	} else {
		c.JSON(400, "bind fail")
	}

}
func LoginAdmin(c *gin.Context) {
	var loginadminservice service.AdminService
	if err := c.ShouldBind(&loginadminservice); err == nil {
		res := loginadminservice.AdminLogin(c.Request.Context())
		c.JSON(200, res)
	} else {
		c.JSON(400, "bind fail")
	}

}
